package com.joysuch.wwyt.bp.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.joysuch.wwyt.bp.bean.contractor.BpContractorViolationRecordBean;
import com.joysuch.wwyt.bp.service.BpContractorViolationRecordsManagementService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/report-api/bp")
@Api(tags = "承包商-违章")
public class BpReportController {
    @Autowired
    private BpContractorViolationRecordsManagementService service;

    @ApiOperation(value = "承包商在一段时间内的违章记录查询")
    @GetMapping("getViolation")
    public JSONObject getViolationRecords(String contractorName, Date beginTime, Date endTime,Integer pageNo,Integer pageSize){
        IPage<BpContractorViolationRecordBean> data = service.getViolationRecordsByContractor(contractorName,beginTime,endTime,pageNo,pageSize);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data",data.getRecords());
        jsonObject.put("total",(data.getTotal() + pageSize - 1)/pageSize);
        jsonObject.put("count",data.getRecords().size());
        return jsonObject;
    }
}
